CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR cortex-m7)
#SET(CMAKE_VERBOSE_MAKEFILE ON)

SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)

SET(CMAKE_C_COMPILER "D:/rtttools/env-windows-v1.3.5/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-gcc.exe")
SET(CMAKE_ASM_COMPILER "D:/rtttools/env-windows-v1.3.5/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-gcc.exe")
SET(CMAKE_C_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -std=c99")
SET(CMAKE_ASM_FLAGS " -c -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb  -gdwarf-2")
SET(CMAKE_C_COMPILER_WORKS TRUE)

SET(CMAKE_CXX_COMPILER "D:/rtttools/env-windows-v1.3.5/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-g++.exe")
SET(CMAKE_CXX_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g")
SET(CMAKE_CXX_COMPILER_WORKS TRUE)

SET(CMAKE_OBJCOPY "D:/rtttools/env-windows-v1.3.5/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-objcopy.exe")
SET(CMAKE_SIZE "D:/rtttools/env-windows-v1.3.5/tools/ConEmu/ConEmu/../../../tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-size.exe")

SET(CMAKE_EXE_LINKER_FLAGS " -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,Reset_Handler -T ${CMAKE_SOURCE_DIR}/board/linker_scripts/link.lds")

SET(CMAKE_CXX_STANDARD 14)
PROJECT(rtthread C CXX ASM)
INCLUDE_DIRECTORIES(
	packages/agile_button-v1.1.1/inc
	packages/agile_led-v1.1.1/inc
	bsp
	../../../components/libc/compilers/common/include
	../../../components/libc/compilers/newlib
	../../../libcpu/arm/common
	../../../libcpu/arm/cortex-m7
	../../../components/drivers/include
	../../../components/drivers/spi
	../../../components/drivers/spi/sfud/inc
	board
	board/CubeMX_Config/Inc
	board/ports
	../libraries/HAL_Drivers
	../libraries/HAL_Drivers/config
	../libraries/HAL_Drivers/CMSIS/Include
	../libraries/HAL_Drivers/drv_flash
	../../../components/fal/inc
	../../../components/dfs/dfs_v1/include
	../../../components/dfs/dfs_v1/filesystems/devfs
	../../../components/dfs/dfs_v1/filesystems/elmfat
	../../../components/finsh
	.
	../../../include
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Inc
	../libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Include
	packages/mem_sandbox-latest
	packages/optparse-latest
	../../../components/libc/posix/io/poll
	../../../components/libc/posix/io/stdio
	../../../components/libc/posix/io/termios
	../../../components/libc/posix/ipc
	thread
)

ADD_DEFINITIONS(
	-DRT_USING_LIBC
	-DRT_USING_NEWLIBC
	-DSTM32H743xx
	-DUSE_HAL_DRIVER
	-D_POSIX_C_SOURCE=1
	-D__RTTHREAD__
)

SET(PROJECT_SOURCES
	packages/agile_button-v1.1.1/src/agile_button.c
	packages/agile_led-v1.1.1/src/agile_led.c
	applications/main.c
	bsp/filesys.c
	bsp/bsp_pkgs.c
	bsp/bsp_agile_leds.c
	bsp/bsp_agile_button.c
	../../../components/libc/compilers/common/cctype.c
	../../../components/libc/compilers/common/cstdio.c
	../../../components/libc/compilers/common/cstdlib.c
	../../../components/libc/compilers/common/cstring.c
	../../../components/libc/compilers/common/ctime.c
	../../../components/libc/compilers/common/cwchar.c
	../../../components/libc/compilers/newlib/syscalls.c
	../../../libcpu/arm/common/atomic_arm.c
	../../../libcpu/arm/common/div0.c
	../../../libcpu/arm/common/showmem.c
	../../../libcpu/arm/cortex-m7/context_gcc.S
	../../../libcpu/arm/cortex-m7/cpu_cache.c
	../../../libcpu/arm/cortex-m7/cpuport.c
	../../../components/drivers/ipc/completion.c
	../../../components/drivers/ipc/dataqueue.c
	../../../components/drivers/ipc/pipe.c
	../../../components/drivers/ipc/ringblk_buf.c
	../../../components/drivers/ipc/ringbuffer.c
	../../../components/drivers/ipc/waitqueue.c
	../../../components/drivers/ipc/workqueue.c
	../../../components/drivers/misc/pin.c
	../../../components/drivers/rtc/rtc.c
	../../../components/drivers/serial/serial.c
	../../../components/drivers/spi/qspi_core.c
	../../../components/drivers/spi/sfud/src/sfud.c
	../../../components/drivers/spi/sfud/src/sfud_sfdp.c
	../../../components/drivers/spi/spi_core.c
	../../../components/drivers/spi/spi_dev.c
	../../../components/drivers/spi/spi_flash_sfud.c
	../libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h743xx.s
	board/CubeMX_Config/Src/stm32h7xx_hal_msp.c
	board/board.c
	board/drv_mpu.c
	board/ports/drv_qspi_flash.c
	../libraries/HAL_Drivers/drv_common.c
	../libraries/HAL_Drivers/drv_flash/drv_flash_h7.c
	../libraries/HAL_Drivers/drv_gpio.c
	../libraries/HAL_Drivers/drv_qspi.c
	../libraries/HAL_Drivers/drv_rtc.c
	../libraries/HAL_Drivers/drv_sdram.c
	../libraries/HAL_Drivers/drv_spi.c
	../libraries/HAL_Drivers/drv_usart.c
	../../../components/fal/samples/porting/fal_flash_sfud_port.c
	../../../components/fal/src/fal_rtt.c
	../../../components/fal/src/fal_flash.c
	../../../components/fal/src/fal.c
	../../../components/fal/src/fal_partition.c
	../../../components/dfs/dfs_v1/filesystems/devfs/devfs.c
	../../../components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c
	../../../components/dfs/dfs_v1/filesystems/elmfat/ff.c
	../../../components/dfs/dfs_v1/filesystems/elmfat/ffunicode.c
	../../../components/dfs/dfs_v1/src/dfs.c
	../../../components/dfs/dfs_v1/src/dfs_file.c
	../../../components/dfs/dfs_v1/src/dfs_fs.c
	../../../components/dfs/dfs_v1/src/dfs_posix.c
	../../../components/finsh/shell.c
	../../../components/finsh/msh.c
	../../../components/finsh/msh_parse.c
	../../../components/finsh/cmd.c
	../../../components/finsh/msh_file.c
	../../../src/clock.c
	../../../src/components.c
	../../../src/device.c
	../../../src/idle.c
	../../../src/ipc.c
	../../../src/irq.c
	../../../src/kservice.c
	../../../src/mem.c
	../../../src/mempool.c
	../../../src/object.c
	../../../src/scheduler_up.c
	../../../src/thread.c
	../../../src/timer.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sram.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp_ex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc_ex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_ll_fmc.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cryp.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_usart.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sdram.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart_ex.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_uart.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_comp.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rng.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cec.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c
	../libraries/STM32H7xx_HAL/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c
	../libraries/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/system_stm32h7xx.c
	packages/mem_sandbox-latest/mem_sandbox.c
	packages/optparse-latest/optparse.c
	../../../components/libc/posix/io/poll/poll.c
	../../../components/libc/posix/io/stdio/libc.c
	../../../components/libc/posix/io/termios/termios.c
	thread/thread_startup.c
	thread/Event.c
	thread/bsp_cmd.c
	packages/vi-latest/vi.c
	packages/vi-latest/vi_utils.c
)

LINK_DIRECTORIES(
)

LINK_LIBRARIES(
	c
	m
)

ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})
ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD 
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)